<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://system">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../admin.xsl" />
	<xsl:include href="../cp/path.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
		</head>
		<body>
			<xsl:call-template name="admin-header" />
			
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<div id="path">
			<xsl:apply-templates select="document('xmodule://cp/getPath/0;system;regedit')/data/response" mode="cp-path" />
		</div>
		
		<h1>Редактирование реестра</h1>
		
		<xsl:apply-templates select="message" />
		
		<a name="form" />
		<form action="{$baseURI}/admin/system/regedit/" method="post">
			<p>
				<xsl:text>Ключ: </xsl:text>
				<xsl:if test="@edit = 1">
					<input type="hidden" name="key" value="{@key}" />
					
					<b>
						<xsl:value-of select="@key" />
					</b>
					
					<xsl:text> </xsl:text>
					<input type="text" size="15" name="value">
						<xsl:attribute name="value">
							<xsl:value-of select="value" />
						</xsl:attribute>
					</input>
					
					<xsl:text> </xsl:text>
					<input type="submit" value="сохранить" class="important" />
					<xsl:text> </xsl:text>
					<input type="button" value="отмена" onclick="document.location.href=baseURI+'/admin/system/regedit'" />
				</xsl:if>
				
				<xsl:if test="@edit = 0">
					<input type="text" name="key" size="30" value="{@key}" />
					<xsl:text> </xsl:text>
					<input type="submit" value="редактировать" />
				</xsl:if>
			</p>
		</form>
		
		<form style="display:none;" action="{$baseURI}/admin/system/regedit/" name="hiddenregedit" method="post">
			<input type="hidden" name="key" id="hidden_key" />
		</form>
		
		<xsl:if test="@edit = 0">
			<h2>Новый ключ</h2>
			
			<form action="{$baseURI}/admin/system/regedit/" method="post">
				<table>
					<tbody>
						<tr>
							<td>Ключ:</td>
							<td><input type="text" name="new_key" size="30" value="" /></td>
						</tr>
						<tr>
							<td>Значение:</td>
							<td><input type="text" name="new_value" size="30" value="" /></td>
						</tr>
						<tr>
							<td>Помощь:</td>
							<td><input type="text" name="new_help" size="30" value="" /></td>
						</tr>
					</tbody>
				</table>
				<p>
					<input type="submit" name="create" value="Создать" />
				</p>	
			</form>
		</xsl:if>
		
		<h2>Помощь</h2>
		
		<table class="standart" cellspacing="0" cellpadding="0">
			<tbody>			
				<xsl:apply-templates select="helpers" />
			</tbody>
		</table>
		
		<script type="text/javascript">
			function goKey (key) {
				document.getElementById('hidden_key').value = key;
				document.hiddenregedit.submit ();
			}
		</script>
	</xsl:template>
	
	<xsl:template match="helpers/item">
		<tr>
			<td>
				<a href="{$baseURI}/admin/system/regedit" title="Редактировать">
					<xsl:attribute name="onclick">
						<xsl:text>goKey('</xsl:text>
						<xsl:value-of select="key" />
						<xsl:text>');return false;</xsl:text>
					</xsl:attribute>
					<xsl:value-of select="key" />
				</a>
			</td>
			<td>
				<xsl:value-of select="help" />
			</td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>